using System;
using System.Collections.Generic;
using System.Linq;

namespace Rosetta.Default.AddIns.Text
{
    public sealed class StringConverter : Converter
    {
        #region Constructors

        public StringConverter()
            : base("String Converter")
        {
            Category = "Text";

            Add<string, string, string, string>("ConcatThree", ConcatThree);
            Add<string, string, string>("ConcatTwo", ConcatTwo);
            Add<string, string, bool>("Contains", Contains, "input", "value");
            Add<string, IEnumerable<string>, string>("Join", Join, "separator", "value");
        }

        #endregion

        #region Class Methods

        private static string ConcatThree(string str0, string str1, string str2)
        {
            return string.Concat(str0, str1, str2);
        }

        private static string ConcatTwo(string str0, string str1)
        {
            return string.Concat(str0, str1);
        }

        private static bool Contains([NotNull] string input, [NotNull] string value)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            return input.Contains(value);
        }

        private static string Join(string separator, [NotNull] IEnumerable<string> value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            return string.Join(separator, value.ToArray());
        }

        #endregion
    }
}